<?php include('../common/pdata_mysql.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>更新变电站</title>
<style type="text/css">
.modi input {
	width: 350px;
	height: 30px;
}
.modi textarea {
	width: 350px;
	height: 50px;
}
.modi {
	font-size: 10px;
	width: 960px;
}
#stEdit {
	float: left;
	width: 960px;
}
</style>
<link href="/css/allstyle.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="header">
  <?php include("../common/header.php") ?>
</div>
<?php
	
	if(isset($_REQUEST['update']))
	{//当传递过来的是stcode的时候，判断为更新查看及可以进行添加操作
		$stid = $_REQUEST['stid'];
		$stcode = $_REQUEST['stcode'];
		$stname = $_REQUEST['stname'];
		$stowner = $_REQUEST['stowner'];
		$stlvl = $_REQUEST['stlvl'];
		$stoldname = $_REQUEST['stoldname'];
		$strunstart = $_REQUEST['strunstart'];
		$transnum = $_REQUEST['transnum'];
		$highvolt = $_REQUEST['highvolt'];
		$midvolt = $_REQUEST['midvolt'];
		$lowvolt = $_REQUEST['lowvolt'];
		$transcap = $_REQUEST['transcap'];
		$highline = $_REQUEST['highline'];
		$midline = $_REQUEST['midline'];
		$lowline = $_REQUEST['lowline'];
		$capreactive = $_REQUEST['capreactive'];
		$indreactive = $_REQUEST['indreactive'];
		$starea = $_REQUEST['starea'];
		$allbuildarea = $_REQUEST['allbuildarea'];
		$mainbuildarea = $_REQUEST['mainbuildarea'];
		$location = $_REQUEST['location'];
		$stkind = $_REQUEST['stkind'];
		$remark = $_REQUEST['remark'];
		$stgps = $_REQUEST['stgps'];
		$running = $_REQUEST['running'];
		
		$sql = "UPDATE stations SET ".
		"stcode = '".$stcode."',".
		"stname = '".$stname."',".
		"stowner = '".$stowner."',".
		"stlvl = '".$stlvl."',".
		"stoldname = '".$stoldname."',".
		"strunstart = '".$strunstart."',".
		"transnum = '".$transnum."',".
		"transcap = '".$transcap."',".
		"highvolt = '".$highvolt."',".
		"highline = '".$highline."',".
		"midvolt = '".$midvolt."',".
		"midline = '".$midline."',".
		"lowvolt = '".$lowvolt."',".
		"lowline = '".$lowline."',".
		"capreactive = '".$capreactive."',".
		"indreactive = '".$indreactive."',".
		"starea = '".$starea."',".
		"allbuildarea = '".$allbuildarea."',".
		"mainbuildarea = '".$mainbuildarea."',".
		"location = '".$location."',".
		"stkind = '".$stkind."',".
		"remark = '".$remark."',".
		"stgps = '".$stgps."',".
		"running = '".$running."' ".
		"WHERE stid = ".$stid
		;
		
		echo "<p>".$sql."</p>";
		//update数据
		$conn = mysql_pconnect($hostname_pdata, $username_pdata, $password_pdata);
		mysql_select_db("pdata"); 
		if(mysql_query($sql,$conn) or die(mysql_error()))
		{		
			//重新读取，查询更新后的数据
			$sql = "select * from stations where stid = ". $stid;
			$rs = mysql_query($sql,$conn);
			$row = mysql_fetch_array($rs) or die(mysql_error()); 
			//$stid = $row['stid'];
			$stcode = $row['stcode'];
			$stname = $row['stname'];
			$stowner = $row['stowner'];
			$stlvl = $row['stlvl'];
			$stoldname = $row['stoldname'];
			$strunstart = $row['strunstart'];
			$transnum = $row['transnum'];
			$transcap = $row['transcap'];
			$highvolt = $row['highvolt'];
			$highline = $row['highline'];
			$midvolt = $row['midvolt'];
			$midline = $row['midline'];
			$lowvolt = $row['lowvolt'];
			$lowline = $row['lowline'];
			$capreactive = $row['capreactive'];
			$indreactive = $row['indreactive'];
			$starea = $row['starea'];
			$allbuildarea = $row['allbuildarea'];
			$mainbuildarea = $row['mainbuildarea'];
			$location = $row['location'];
			$stkind = $row['stkind'];
			$remark = $row['remark'];
			$stgps = $row['stgps'];
			$running = $row['running'];
		}
		else
		{
			echo "UPDATE missed!Check the data and update again!";
		}
		
		mysql_close($conn);

	
	}
  	elseif( isset($_REQUEST['stid']) )
	{//当传递过来的是stid的时候，判断为读取数据库，查看需要更新的情况。
	//此时可以修改数据，并且将对数据库进行更新。
		$stid = intval($_REQUEST['stid']);
		  	
		$conn = mysql_pconnect($hostname_pdata, $username_pdata, $password_pdata);
		mysql_select_db("pdata"); 
		$sql = "select * from stations where stid = ". $stid;
		$rs = mysql_query($sql,$conn);
		
		$row = mysql_fetch_array($rs) or die(mysql_error()); 
		//$stid = $row['stid'];
		$stcode = $row['stcode'];
		$stname = $row['stname'];
		$stowner = $row['stowner'];
		$stlvl = $row['stlvl'];
		$stoldname = $row['stoldname'];
		$strunstart = $row['strunstart'];
		$transnum = $row['transnum'];
		$transcap = $row['transcap'];
		$highvolt = $row['highvolt'];
		$highline = $row['highline'];
		$midvolt = $row['midvolt'];
		$midline = $row['midline'];
		$lowvolt = $row['lowvolt'];
		$lowline = $row['lowline'];
		$capreactive = $row['capreactive'];
		$indreactive = $row['indreactive'];
		$starea = $row['starea'];
		$allbuildarea = $row['allbuildarea'];
		$mainbuildarea = $row['mainbuildarea'];
		$location = $row['location'];
		$stkind = $row['stkind'];
		$remark = $row['remark'];
		$stgps = $row['stgps'];
		$running = $row['running'];

		mysql_close($conn);
	}
	else
	{
		$stid = "";
		$stcode = "";
		$stname = "";
		$stowner = "";
		$stlvl = "";
		$stoldname = "";
		$strunstart = "";
		$transnum = "";
		$highvolt = "";
		$midvolt = "";
		$lowvolt = "";
		$transcap = "";
		$highline = "";
		$midline = "";
		$lowline = "";
		$capreactive = "";
		$indreactive = "";
		$starea = "";
		$allbuildarea = "";
		$mainbuildarea = "";
		$location = "";
		$stkind = "";
		$remark = "";
		$stgps = "";
		$running = 0;
	}?>
<div id="wrap">
    <h1>正在修改：<?php echo $stname;?></h1>
    <form id="station" name="station" method="post" action="st_edit.php">
      <!--传递给自己--> 
      <!--      <input name="insert" type="submit" id="insert" value="插入" disabled="disabled" />
-->
      <input name="update" type="submit" id="update" value="更新" />
      <table class="modi">
        <tr>
          <th width="100">项目</th>
          <th width="400">内容</th>
          <th width="100">项目</th>
          <th width="400">内容</th>
        </tr>
        <tr>
          <td>变电站序号</td>
          <td><input name="stid" type="text" id="stid" value="<?php echo $stid; ?>" readonly="readonly"  /></td>
          <td>变电站代码</td>
          <td><input name="stcode" type="text" id="stcode" value="<?php echo $stcode; ?>" /></td>
        </tr>
        <tr>
          <td>变电站名称</td>
          <td><input name="stname" type="text" id="stname" value="<?php echo $stname; ?>" /></td>
          <td>曾用名称</td>
          <td><input name="stoldname" type="text" id="stoldname" value="<?php echo $stoldname; ?>" /></td>
        </tr>
        <tr>
          <td>电压等级</td>
          <td><input name="stlvl" type="text" id="stlvl" value="<?php echo $stlvl; ?>" /></td>
          <td>所属供电局</td>
          <td><input name="stowner" type="text" id="stowner" value="<?php echo $stowner; ?>" /></td>
        </tr>
        <tr>
          <td>首次投运时间</td>
          <td><input name="strunstart" type="text" id="strunstart" value="<?php echo $strunstart; ?>" /></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td>变压器数量</td>
          <td><input name="transnum" type="text" id="transnum" value="<?php echo $transnum; ?>" /></td>
          <td>变压器容量</td>
          <td><input name="transcap" type="text" id="transcap" value="<?php echo $transcap; ?>" /></td>
        </tr>
        <tr>
          <td>高压电压</td>
          <td><input name="highvolt" type="text" id="highvolt" value="<?php echo $highvolt; ?>" /></td>
          <td>高压出线</td>
          <td><input name="highline" type="text" id="highline" value="<?php echo $highline; ?>" /></td>
        </tr>
        <tr>
          <td>中压电压</td>
          <td><input name="midvolt" type="text" id="midvolt" value="<?php echo $midvolt; ?>" /></td>
          <td>中压出线</td>
          <td><input name="midline" type="text" id="midline" value="<?php echo $midline; ?>" /></td>
        </tr>
        <tr>
          <td>低压电压</td>
          <td><input name="lowvolt" type="text" id="lowvolt" value="<?php echo $lowvolt; ?>" /></td>
          <td>低压出线</td>
          <td><input name="lowline" type="text" id="lowline" value="<?php echo $lowline;; ?>" /></td>
        </tr>
        <tr>
          <td>容性无功补偿</td>
          <td><input name="capreactive" type="text" id="capreactive" value="<?php echo $capreactive; ?>" /></td>
          <td>感性无功补偿</td>
          <td><input name="indreactive" type="text" id="indreactive" value="<?php echo $indreactive; ?>" /></td>
        </tr>
        <tr>
          <td>围墙内面积</td>
          <td><input name="starea" type="text" id="starea" value="<?php echo $starea; ?>" /></td>
          <td>变电站类型</td>
          <td><input name="stkind" type="text" id="stkind" value="<?php echo $stkind; ?>" /></td>
        </tr>
        <tr>
          <td>全站建筑面积</td>
          <td><input name="allbuildarea" type="text" id="allbuildarea" value="<?php echo $allbuildarea; ?>" /></td>
          <td>主控楼面积</td>
          <td><input name="mainbuildarea" type="text" id="mainbuildarea" value="<?php echo $mainbuildarea; ?>" /></td>
        </tr>
        <tr>
          <td>GPS地址</td>
          <td><input name="stgps" type="text" id="stgps" value="<?php echo $stgps; ?>" /></td>
          <td>是否运行？</td>
          <td><input name="running" type="text" id="running" value="<?php echo $running; ?>" /></td>
        </tr>
        <tr>
          <td>站址位置</td>
          <td><textarea name="location" id="location"><?php echo $location; ?></textarea></td>
          <td>备　　注</td>
          <td><textarea name="remark" id="remark"><?php echo $remark; ?></textarea></td>
        </tr>
      </table>
    </form>
</div>
<div id="footer">
  <?php include("../common/footer.php") ?>
</div>
</body>
</html>